<template>
  <div class="login">
    <div class="phone" >
      <div class="title">泉盈电站后台管理系统</div>
      <div class="inputItem">
        <img class="inputItem_label" src="../../static/img/login/1.png"/>
        <div class="inputItem_inputWrapper">
          <uni-easyinput v-model="loginname"
                         :inputBorder="false"
                         placeholder="请输入账号"></uni-easyinput>
        </div>
      </div>

      <div class="inputItem">
        <img class="inputItem_label" src="../../static/img/login/2.png"/>
        <div class="inputItem_inputWrapper">
          <uni-easyinput v-model="passwd" password
                         :inputBorder="false"
                         placeholder="请输入密码"></uni-easyinput>
        </div>
      </div>
      <div class="login_btn_phone" @tap="loginAdmin">登录</div>
    </div>
  </div>
</template>

<script>
  import LoginManager from "@/utils/LoginManager";
  import wxPromisify from "@/libs/wxPromisify";
  import Http from "@/libs/Http";

  export default {
    name: "adminIndex",
    data() {
      return {
        loginname: '',
        passwd: ''
      }
    },
    methods: {
      async loginAdmin() {
        console.log('aaaa');
        if (!this.loginname) {
          wx.showToast({
            title: '请输入用户名',
            icon: 'none',
            duration: 2000
          })
          return
        }
        if (!this.passwd) {
          wx.showToast({
            title: '请输入密码',
            icon: 'none',
            duration: 2000
          })
          return
        }
        let loginRes = await wxPromisify.login();
        console.log('loginRes:', loginRes);
        console.log('code:', loginRes.code);
        let param={
            loginname:this.loginname,
            passwd:this.passwd,
            code:loginRes.code,
        }
        let {returnCode, resultData} = await LoginManager.loginByAdmin(param);
        if (returnCode == 0) {
          wx.showToast({
            title: '登录成功',
            icon: 'none',
            duration: 2000
          });
          wx.navigateBack();
        }else{
          wx.showToast({
            title: '账号或密码错误，请重新输入',
            icon: 'none',
            duration: 2000
          });
        }
      },
    },
  }
</script>

<style scoped lang="scss">
  .login {
    text-align: center;
  }

  .tip {
    margin-top: 40px;
    font-size: 32px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
  }

  .weixin {
    .logo {
      width: 270px;
      height: 76px;
      margin-top: 260px;
    }

    .login_btn {
      display: inline-flex;
      align-items: center;
      margin-top: 260px;
      width: 630px;
      height: 92px;
      background: #0ABA07;
      border-radius: 46px;
      font-size: 32px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #FFFFFF;

      .login_btn_weixin {
        width: 64px;
        height: 52px;
        margin-left: 84px;
        margin-right: 48px;
      }

      .login_btn_bindAccount {
        background: transparent;
        border: 0;
        outline: none;
        color: white;
        padding: 0;
      }
    }
  }

  .phone {
    margin-top: 110px;
  }

  .title {
    font-size: 40px;
    text-align: center;
    color: #308ac5;
    margin-bottom: 20px;
  }

  .inputItem {
    display: flex;
    align-items: center;
    height: 116px;
    margin-left: 70px;
    margin-right: 50px;
    border-bottom: 1px solid #E6E6E6;

    .inputItem_label {
      width: 34px;
      height: 40px;
    }

    .inputItem_inputWrapper {
      flex: 1;
      display: inline-block;
      margin-left: 38px;
    }

    .inputItem_getCode {
      font-size: 32px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #D9261D;
      margin-right: 32px;
    }

  }

  .login_btn_phone {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 80px;
    background: #D9261D;
    border-radius: 16px;
    font-size: 32px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #FFFFFF;
    margin-top: 160px;
    margin-right: 60px;
    margin-left: 60px;
  }

</style>